package leetcode_core.leetcode_5;

import java.util.Arrays;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年01月03日 12:30
 */
public class CanPermutePalindrome {
    public boolean canPermutePalindrome(String s) {
        char[] chars = s.toCharArray();
        Arrays.sort(chars);
        boolean flag = false;
        int i = 0;
        while (i<chars.length){
            int cnt = 0;
            char sChar = chars[i];
            while (i<chars.length && sChar == chars[i]){
                i++;cnt++;
            }
            if(cnt %2 !=0){
                if(!flag){
                    flag = !flag;
                }else{
                    return false;
                }
            }
        }
        return true;
    }
}
